﻿using DevExpress.XtraCharts;
using DevTeam;
using System;
using System.Data;
using System.Drawing;

namespace ConfExpert.Forms.Depo
{
    public partial class ArtColors : XPopupForm
    {
        int ProductId;
        public ArtColors(int _ProductId)
        {
            InitializeComponent();
            ProductId = _ProductId;
        }

        private void ArtColors_Load(object sender, EventArgs e)
        {
            
            


            //pieChart.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Flat;
            // Create a pie series.
            Series series1 = new Series("Clr", ViewType.Bar);

            // Add the series to the chart.
            pieChart.Series.Add(series1);

            DataTable dt = ExecuteDataTable("GetArtColors", ProductId);
            pieChart.DataSource = dt;

            // Specify data members to bind the series.
            series1.ArgumentScaleType = ScaleType.Qualitative;
            series1.ArgumentDataMember = "Clr";
            series1.ValueScaleType = ScaleType.Numerical;
            series1.ValueDataMembers.AddRange(new string[] { "Val" });

            //((SideBySideBarSeriesView)series1.View).ColorEach = true;

            // Set some properties to get a nice-looking chart.
            //((BarSeriesView)series1.View).ColorEach = true;
            //((XYDiagram)pieChart.Diagram).AxisY.Visible = false;
            //pieChart.Legend.Visible = false;
            
            // Adjust the point options of the series.
            series1.Label.PointOptions.PointView = PointView.ArgumentAndValues;
            ((BarSeriesView)series1.View).Color = Color.White;
            //series1.Label.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
            //series1.Label.PointOptions.ValueNumericOptions.Precision = 0;

            // Detect overlapping of series labels.
            ((BarSeriesLabel)series1.Label).ResolveOverlappingMode = ResolveOverlappingMode.Default;

            // Access the view-type-specific options of the series.
            //BarSeriesView myView = (BarSeriesView)series1.View;

            // Specify a data filter to explode points.
            //myView.ExplodedPointsFilters.Add(new SeriesPointFilter(SeriesPointKey.Value_1,
            //    DataFilterCondition.GreaterThanOrEqual, 9));
            //myView.ExplodedPointsFilters.Add(new SeriesPointFilter(SeriesPointKey.Argument,
            //    DataFilterCondition.NotEqual, "Others"));
            //myView.ExplodeMode = PieExplodeMode.UseFilters;
            //myView.ExplodedDistancePercentage = 30;
            //myView.RuntimeExploding = true;
            //myView.HeightToWidthRatio = 0.75;

            // Hide the legend (if necessary).
            pieChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;



            //SideBySideBarSeriesView view = (SideBySideBarSeriesView)pieChart.Series[0].View;
            //view.FillStyle.FillMode = FillMode.Solid;
            pieChart.CustomDrawSeriesPoint += pieChart_CustomDrawSeriesPoint;


            /*
             * 
string paletteName = "paletteName";
PaletteEntry paletteEntry = new PaletteEntry(Colors[0]);
Palette myPalette = new Palette(paletteName, new PaletteEntry[] { paletteEntry });
for (int i = 1; i < Colors.Length; i++) {
paletteEntry = new PaletteEntry(Colors[i]);
myPalette.Add(paletteEntry);
chartName.PaletteRepository.Add(paletteName, myPalette);
}
chartName.PaletteName = paletteName;
             *
             */

        }

        void pieChart_CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e)
        {
            ((BarDrawOptions)e.SeriesDrawOptions).FillStyle.FillMode = FillMode.Solid;
            //string[] clrs = ",Black,Blue,Navy,Red,Yellow,Magenta,Brown,Grey,Green,Teal,Violet,Orange,Pink,White,Cyan".Split(",".ToCharArray());
            //e.SeriesDrawOptions.Color = (Color)Enum.Parse(typeof(Color), e.SeriesPoint.Argument);
            
            switch (e.SeriesPoint.Argument)
            {
                case "Black": e.SeriesDrawOptions.Color = Color.Black; break;
                case "Blue": e.SeriesDrawOptions.Color = Color.Blue; break;
                case "Navy": e.SeriesDrawOptions.Color = Color.Navy; break;
                case "Red": e.SeriesDrawOptions.Color = Color.Red; break;
                case "Yellow": e.SeriesDrawOptions.Color = Color.Yellow; break;
                case "Magenta": e.SeriesDrawOptions.Color = Color.Magenta; break;
                case "Brown": e.SeriesDrawOptions.Color = Color.Brown; break;
                case "Gray": e.SeriesDrawOptions.Color = Color.Gray; break;
                case "Green": e.SeriesDrawOptions.Color = Color.Green; break;
                case "Teal": e.SeriesDrawOptions.Color = Color.Teal; break;
                case "Violet": e.SeriesDrawOptions.Color = Color.Violet; break;
                case "Orange": e.SeriesDrawOptions.Color = Color.Orange; break;
                case "Pink": e.SeriesDrawOptions.Color = Color.Pink; break;
                case "White": e.SeriesDrawOptions.Color = Color.White; break;
                case "Cyan": e.SeriesDrawOptions.Color = Color.Cyan; break;
            }
            
        }

    }
}
